/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.querie.Voldemort;
/**
 *
 * @author Naushin
 */

import voldemort.client.ClientConfig;
import voldemort.client.SocketStoreClientFactory;
import voldemort.client.StoreClient;
import voldemort.client.StoreClientFactory;
import voldemort.versioning.Versioned;
public class VoldemortH {

    private StoreClient<String, String> voldemort;

    public String url="tcp://localhost:6667";

    private StoreClient<String, String> connect(String endPoint, String storeName)throws Exception

    {
       
        StoreClientFactory factory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(endPoint));

        voldemort=factory.getStoreClient(storeName);

       return voldemort;

    }

    public void putValue(String key, String value,String storeName)
    {
    StoreClient<String, String> client;
    try{
    client=connect(url,storeName);
    client.put(key,value);

    }catch(Exception ex){
    System.out.println("Error: "+ex);
    ex.printStackTrace();
    }
    
    }


    public String getValue(String key, String storeName){
        StoreClient<String, String> client;
        Versioned<String> v =null;
        try{
        client=connect(url, storeName);
        v=client.get(key);
        if(v==null){
        return null;
        }
        }catch(Exception ex){
        System.out.println("Error "+ex);
        ex.printStackTrace();
        }

        return v.getValue();
    }
    public void delValue(String key, String storeName){
        StoreClient<String,String> client;
        try{
        client=connect(url,storeName);
        client.delete(key);

        }
        catch(Exception ex){
        ex.printStackTrace();
        }
    }
   
}
